$(function(){
	if(getCookie("password")){
		$("#name").textbox("setValue",getCookie("name"));
		$("#password").textbox("setValue",getCookie("password"));
	}else{
		$("#name").textbox("setValue",'');
		$("#password").textbox("setValue",'');
	}
});
//登陆
function loginSumbit(){
	var name=$("#name").textbox("getValue");
	var password=$("#password").textbox("getValue");
	var code=$("#code").textbox("getValue");
	var isrememberMe=$("#rememberMe").is(":checked");
	if(isrememberMe){
		addCookie(name,password);
	}else{
		deleteCookie("name");
		deleteCookie("password");
	}
	if(""==name){
		if(""==password){
			 $.messager.alert('提示',"用户名和密码不能为空");
			 return;
			}else{
			 $.messager.alert('提示',"用户名不能为空");	
			 return;
			}
	}else{
		if(""==password){
		 $.messager.alert('提示',"密码不能为空");
		 return;
		}else{
			if(""==code){
				$.messager.alert('提示',"请先填写验证码");
				 return;	
			}
			$("#loginForm").submit();
		}
	}
}
//把用户名和密码加入Cookie
function addCookie(name,password){
	  var date=new Date;
	  date.setTime(date.getTime()+7*24*60*60*1000);
	  document.cookie="name="+name;
	  document.cookie="password="+password;
	  document.cookie="expires="+date.toGMTString();
}
//删除Cookie
function deleteCookie(name){
	var date=new Date(); 
	date.setTime(date.getTime()-10000); 
	document.cookie=name+"='';expires="+date.toGMTString(); 
}
//通过名称获得Cookie值
function getCookie(name){
	var singleCookie;
	var CookieArry=document.cookie.split(";");
	for(var i=0;i<CookieArry.length;i++){
		var singleCookieArry=CookieArry[i].split("=");
		if(singleCookieArry[0].trim()==name){
			singleCookie=singleCookieArry[1];
			return singleCookie;
		}
	}
	return singleCookie;
}

